<template>
	<view class="register">
		<view class="register-head">
			<!-- 自定义状态栏高度 -->
			<view class="head-nav"></view>
			<view class="head-content">
				<view class="head-return" @click="navigateBack">
					<text class="iconfont iconback_light"></text>
					{{ registerHeadText }}
				</view>
				<view class="head-portrait" v-if="bindStorage">
					<image
						:src="userInfo.avatar ? $util.img(userInfo.avatar) : $util.img('upload/uniapp/default_head.png')">
					</image>
				</view>
			</view>
		</view>
		<view class="register-body">
			<view class="form-input">
				<input class="uni-input" type="text" maxlength="30" placeholder="营业执照全称" v-model="username" />
			</view>
			<view class="form-input">
				<input class="uni-input" type="password" maxlength="30" placeholder="密码" v-model="password" />
			</view>
			<view class="form-input">
				<input class="uni-input" type="text" maxlength="11" placeholder="请输入手机号码" v-model="phone" />
			</view>
			<view class="form-input">
				<picker :range="value" @change="selectValue" :style="{color:typeValue?'':'grey'}">{{typeValue?value[typeValue-1]:'请选择类型'}}</picker>
			</view>
			<view class="form-input">
				<input class="uni-input" type="text" maxlength="30" placeholder="请输入邀请码" v-model="invite" />
			</view>
			<view class="form-input">
				<input class="uni-input" type="text" maxlength="30" placeholder="请输入所在地XX省XX市XX区/县" v-model="address" />
			</view>
			<button type="primary" class="register-btn" @tap="register">完成注册，并登录</button>
		</view>
	</view>
</template>

<script>
	import http from 'common/js/http.js';
	export default {
		data() {
			return {
				value:['药店','诊所'],
				username: '',
				password: '',
				invite: '',
				phone: '',
				address:'',
				bindStorage: null,
				isAuthorize: 0, // 是否授权
				registerHeadText: '注册',
				registerMode: 'mobile', //注册方式
				typeValue:''
			};
		},
		onLoad() {

		},
		methods: {
			selectValue(e){
				this.typeValue = e.detail.value+1
				console.log("eeeeeeeeeeeeeee",e)
			},
			navigateBack() {
				this.$util.redirectTo('/pages/login/login/login', '', '', 'reLaunch');
			},
			register() {
				console.log("进来了========================")
				// var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
				// var phoneNum = this.phone;//手机号码
				// var  flag = reg.test(phoneNum); //true
				if (!this.username) {
					uni.showToast({
						title: '账号不能为空',
						icon:'none',
						duration:3000
					})
				} else if (!this.password) {
					uni.showToast({
						title: '密码不能为空',
						icon:'none',
						duration:3000
					})
				} else if (!this.invite) {
					uni.showToast({
						title: '邀请码不能为空',
						icon:'none',
						duration:3000
					})
				} else if (!this.phone) {
					uni.showToast({
						title: '手机号码不能为空',
						icon:'none',
						duration:3000
					})
				}else if (!this.address) {
					uni.showToast({
						title: '所在地不能为空',
						icon:'none',
						duration:3000
					})
				}else if (!this.typeValue) {
					uni.showToast({
						title: '请选择类型',
						icon:'none',
						duration:3000
					})
				}
				//  else if(flag== false){
				// 	uni.showToast({
				// 		title: '手机号码格式不正确',
				// 		icon:'none',
				// 		duration:3000
				// 	})
				// }
				else {
					this.sendRequest({
						url: 'System.UniApp.register',
						data: {
							username: this.username,
							password: this.password,
							invite: this.invite,
							phone: this.phone,
							address: this.address,
							user_type:this.typeValue
						},
						success: res => {
							console.log('注册结果=',res)
							if (res.code == 1) {
								// this.sendRequest({
								// 	url: 'System.Distribution.applyPromoter',
								// 	data: { promoter_shop_name: this.username },
								// 	success: res => {
								// 		if (res.data > 0) {
								// 			this.$util.showToast({
								// 				title: '已提交申请,等待审核'
								// 			});
								// 		} else {
								// 			this.flag = true;
								// 			this.$util.showToast({
								// 				title: '申请失败,等待审核'
								// 			});
								// 		}
								// 	}
								// });
								
								
								uni.showModal({
									title: res.message,
									content: '现在登录',
									confirmText: '登录',
									cancelText: '取消',
									success: function(res) {
										if (res.confirm) {
											// 立即申请
											uni.navigateTo({
												url: '/pages/login/login/login'
											})
											
											
											
											
											console.log('现在登录');
											
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
								// uni.showToast({
								// 	title: res.message
								// })
							} else if (res.code == -1) {
								uni.showToast({
									title: res.message,
									icon:'none',
									duration:3000
								})
							} else if (res.code == -2) {
								uni.showToast({
									title: res.message,
									icon:'none',
									duration:3000
								})
							}
						},
						fail: (fail) => {
							console.log("fail===============",fail)
						},
						complete: (complete) => {
							console.log("complete===============",complete)
						}
					});
				}



			}
		},
		watch: {},
		onShow() {},

		onUnload() {},
		mixins: [http],
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.register-head {

		/* 自定义导航 */
		.head-nav {
			width: 100%;
			height: var(--status-bar-height);
		}

		.head-content {
			position: relative;
			width: 750rpx;
			height: 540rpx;
			background: $base-color url(../../../static/images/authorize_bj.png) no-repeat;
			background-size: contain;

			.head-return {
				padding-left: 30rpx;
				height: 90rpx;
				line-height: 90rpx;
				color: #fff;
				font-size: $ns-font-size-lg;
				text {
					display: inline-block;
					margin-right: 10rpx;
				}
			}
			.head-portrait {
				overflow: hidden;
				position: absolute;
				bottom: 28rpx;
				left: 50%;
				transform: translateX(-50%);
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				border: 4rpx solid #fff;
				image {
					width: 120rpx;
					height: 120rpx;
				}
			}
		}
	}

	.register-body {
		padding: 100rpx 80rpx 0;
		.form-input {
			margin-top: 60rpx;
			height: 60rpx;
			border-bottom: 2rpx solid $ns-bg-color-gray;
			input {
				font-size: $ns-font-size-base;
				padding: 0;
			}
		}

		.input-mobile {
			position: relative;

			text {
				&:after {
					content: '';
					position: absolute;
					left: 56rpx;
					bottom: 24rpx;
					border: 2rpx solid transparent;
					border-top-color: #333;
					border-left-color: #333;
					width: 12rpx;
					height: 12rpx;
					display: block;
					transform: rotate(-135deg);
				}
				position: absolute;
				top: -4rpx;
				left: 0;
			}

			input {
				padding: 0 0 0 90rpx;
			}
		}

		.register-btn {
			margin-top: 60rpx;
		}

		button {
			margin: 0;
			border-radius: 40rpx;
			margin-bottom: 30rpx;
			color: #fff;
		}

		.forget-section {
			display: flex;
			flex-direction: row-reverse;
			justify-content: space-between;
			margin-top: 10rpx;
			height: 70rpx;
			line-height: 70rpx;
		}

		.register-tips {
			margin-top: 20rpx;
			font-size: $ns-font-size-sm;
			text-align: center;
		}

		.register-tips navigator {
			display: inline;
		}

		.wxAccountRegister {
			font-size: $ns-font-size-lg;
			text-align: center;
		}
	}

	/* 注册协议 */
	.conten-box {
		padding: 0 $ns-padding $ns-padding;

		.title {
			line-height: 100rpx;
			font-size: $ns-font-size-lg + 4rpx;
			font-weight: bold;
			color: $base-color;
			border-bottom: 2rpx solid $ns-border-color-gray;
			margin-bottom: $ns-margin;
		}

		.con {
			width: 100%;
			min-height: 600rpx;
			overflow-y: scroll;
			text-align: left;
			text-indent: 50rpx;
		}
	}

	.align-type {
		display: flex;
		justify-content: space-between;
	}
</style>
<style scoped>
	.wap-floating>>>.uni-popup__wrapper-box {
		width: 80%;
		border-radius: 20rpx;
	}
</style>
